<?php 
session_start();
$_SESSION['uid'] = "uid =1"; 

?>
<?php
require_once './data/users.php';
?>
<html>
    <body>
        <h1>login</h1>
        <h4>username:  </h4>
        <h4>password:  </h4>
        <form action="login.php" method="Post">
            <table>
                <tr><td><input type="text" name="username"></td></tr>
                <tr><td><input type="password" name="password"></td></tr>
                <tr><td><input type="submit" name="submit" value="Enter"></td></tr>
            </table>
        </form>
        
        <?php

        ?>
    </body>
</html>
<?php

  if (isset($_POST['submit'])){
      
      $flag = FALSE;
      for($i =0; $i <count($users); $i++){
       if(strcmp($_POST["username"],
               $users[$i]["username"]) == 0 && strcmp($_POST["password"], $users[$i]["password"]) ==0){
           $flag = true;
           break;
          }  else {
          $flag = false;    
          }   
          
      }
      if($flag == true){
          echo $_POST["username"] . "dang hhap thanh cong";
          header("Location: http://localhost:82/hhhai-wed1/films.php?uid=". $users[$index]['id']);
          }else {  
        echo $_POST["username"] . "ID hoac pass khong hop le";     
}
}
?>





